import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        unreadBox: [],
        readBox: [],
        deleteBox: [],
    },
    mutations: {
        setData(state, value){
            value.map((item)=>{
                switch (item.type){
                    case 1:
                        state.unreadBox.push(item);
                        break;
                    case 2:
                        state.readBox.push(item);
                        break;
                    case 3:
                        state.deleteBox.push(item);
                        break;
                }
            });
        },
        checkRead(state, value){
            let readItem = state.unreadBox.splice(value, 1);//[{id:1,text:"222"}]
            state.readBox.unshift(...readItem)
        },
        checkDelete(state, value){
            let deleteItem = state.readBox.splice(value, 1);
            state.deleteBox.unshift(...deleteItem)
        },
        checkUnread(state, value){
            let unreadItem = state.readBox.splice(value, 1);
            state.unreadBox.unshift(...unreadItem)
        },
        checkBack(state, value){
            let readItem = state.deleteBox.splice(value, 1);
            state.readBox.unshift(...readItem)
        },
        allRead(state){
            let unreadList = state.unreadBox.splice(0);
            state.readBox.unshift(...unreadList)
        },
        allDelete(state){
            let readList = state.readBox.splice(0);
            state.deleteBox.unshift(...readList)
        },
        allUnread(state){
            let deleteList = state.deleteBox.splice(0);
            state.unreadBox.unshift(...deleteList)
        },
    },
    actions: {},
    getters: {
        readNum(state){
            return state.readBox.length
        },
        unreadNum(state){
            return state.unreadBox.length
        },
        deleteNum(state){
            return state.deleteBox.length
        }
    },
    modules: {}
})
